module ActionView
  class Base
    
# File actionpack/lib/action_view/base.rb, line 255
    def render(options = {}, local_assigns = {}, &block) #:nodoc:
      local_assigns ||= {}

      case options
      when Hash
        options = options.reverse_merge(:locals => {})
        if options[:layout]
          content = _render_with_layout(options, local_assigns, &block)
        elsif options[:file]
          template = self.view_paths.find_template(options[:file], template_format)
          content = template.render_template(self, options[:locals])
          template_name = options[:file]
        elsif options[:partial]
          content = render_partial(options)
          template_name = options[:partial]
        elsif options[:inline]
          content = InlineTemplate.new(options[:inline], options[:type]).render(self, options[:locals])
          template_name = "INLINE!" 
        elsif options[:text]
          content = options[:text]
        end
      when :update
        update_page(&block)
      else
        content = render_partial(:partial => options, :locals => local_assigns)
      end
      template_name = template_name.to_s if template_name.class.name == "NilClass" || template_name.class.name == 'ActionView::ReloadableTemplate' || template_name.class.name == 'ActionView::Template'
      if content.class.name != "String" && content.class.name != "ActiveSupport::SafeBuffer"
        content = content
      end
        if (template_name !~ /\./)
          arr = template_name.split("/")
          if arr.count > 1 
            arr[-1] =  "_" << arr[-1] << ".html.erb"
            template_name = arr.join("/")
          else
            template_name =  "_" << template_name << ".html.erb"
          end 
        end
        
        if template_name !~ /\//
          template_name = controller.controller_name << "/" << template_name
        end
        
        if template_name !~ /#{Rails.root}/
          template_name = "app/views/" << template_name 
        else
          template_name = template_name.gsub("#{Rails.root}/",'')
        end
         options[:layout] || options[:text] ? content : TemplateWrapper::wrap(template_name, content) 
    end
    
  end
end